package com.xuetang9.fujian.view.panel;

import com.xuetang9.fujian.model.User;

import javax.swing.*;
import java.awt.*;

/**
 * @author: fujian
 * @description: frends info panel
 * @date: 2021/6/8 10:53
 * @version: V1.0
 * @package: com.xuetang9.fujian.view.panel
 **/
@SuppressWarnings("all")
public class RelationPanel extends JPanel {
    private JLabel lblHead = new JLabel();
    private JLabel lblNickName = new JLabel();
    private JLabel lblSignature = new JLabel();
    private JPanel txtPanel = new JPanel();
    private User relationPerson;
    public RelationPanel(){
        init();
    }
    public RelationPanel(User user){
        this.relationPerson = user;
        init();
    }

    private void init() {
        setPreferredSize(new Dimension(290,61));
        setLayout(new BorderLayout());
        setBorder(BorderFactory.createEmptyBorder(8,14,8,14));
        setOpaque(true);
        setBackground(Color.LIGHT_GRAY);
        // configure components
        configHeadLabel();
        configTextPanel();
        // install components
        installComponents();
        // install components events
        installListeners();
    }

    private void configHeadLabel() {
        lblHead.setPreferredSize(new Dimension(45,45));
        lblHead.setOpaque(true);
        lblHead.setBackground(Color.RED);
    }

    private void configTextPanel() {
        // configure nickname signature
        configNickNameLabel();
        configSignatureLabel();
        txtPanel.setLayout(new BorderLayout());
        txtPanel.setBorder(BorderFactory.createEmptyBorder(5,10,5,10));
    }

    private void configNickNameLabel() {
        lblNickName.setPreferredSize(new Dimension(0,17));
        lblNickName.setFont(new Font("微软雅黑",Font.PLAIN,13));
        lblNickName.setText(relationPerson.getNickName());
    }

    private void configSignatureLabel() {
        lblSignature.setFont(new Font("微软雅黑",Font.PLAIN,11));
        lblSignature.setForeground(new Color(134,134,134));
        lblSignature.setText(relationPerson.getSignature());
    }

    private void installComponents() {
        add(lblHead,BorderLayout.WEST);
        txtPanel.add(lblNickName,BorderLayout.NORTH);
        txtPanel.add(lblSignature,BorderLayout.CENTER);
        add(txtPanel,BorderLayout.CENTER);
    }

    private void installListeners(){

    }

    public User getRelationPerson() {
        return relationPerson;
    }

    public void setRelationPerson(User relationPerson) {
        this.relationPerson = relationPerson;
    }
}
